<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>退课</title>

    <script type="text/javascript" th:src="@{/static/layui/layui.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/static/layui/css/layui.css}"/>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>

<form class="layui-form" method="post" id="searchFrm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">课程姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="cname" id="name" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">&nbsp;&nbsp;&nbsp;&nbsp;</label>
        <div class="layui-input-inline">
            <button type="button" class="layui-btn layui-btn-normal  layui-icon layui-icon-search" id="doSearch">查询</button>
            <button type="reset" class="layui-btn layui-btn-warm  layui-icon layui-icon-refresh">重置</button>
        </div>
    </div>
</form>
<!-- 查询结束 -->
<!-- 数据表格开始 -->
<table class="layui-hide" id="userTable" lay-filter="userTable"></table>
<div style="display: none;" id="userToolBar">

</div>

<script type="text/javascript" th:inline="none">

    var tableIns;
    layui.use([ 'jquery', 'layer', 'form', 'table'  ], function() {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;

        //渲染数据表格
        tableIns=table.render({
            elem: '#userTable'   //渲染的目标对象
            ,url:'seld' //数据接口
            ,title: '退课表'//数据导出来的标题
            ,toolbar:"#userToolBar"   //表格的工具条
            ,cellMinWidth:200 //设置列的最小默认宽度
            ,page: 1  //是否启用分页, limits: [10, 20, 30]
            ,limits: [3, 10, 20]
            ,limit: 3//每页数据默认采用3
            ,cols: [
                [   //列表数据
                    {field:'cid', title:'ID',align:'center',width:"70",sort: true}
                    ,{field:'cname', title:'课程名字',align:'center',width:"150"}
                    ,{field:'ccredit', title:'学分',align:'center',width:"70"}
                    ,{field:'cperiod', title:'学时',align:'center',width:"70"}
                    ,{field:'ctname', title:'课程类型',align:'center',width:"100",sort: true}
                    ,{field:'studytype', title:'修学类型',align:'center',width:"100",sort: true}
                    ,{field:'mname', title:'所属专业',align:'center',width:"200"}
                    ,{field:'cselcount', title:'已选人数',align:'center',width:"100",sort: true}
                    ,{field:'cmaxcount', title:'最大人数',align:'center',width:"100"}
                    ,{fixed: '', title:'操作',align:'center',width:'160',templet:function(data){

                            return '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">退课</a>'

                    }}
                ]
            ]
        })
        $("#doSearch").click(function(){
            var params=$("#searchFrm").serialize();//序列化表单

            tableIns.reload({
                url:"seld?"+params
            })
        });


        //监听行工具事件
        table.on('tool(userTable)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if(layEvent === 'del'){ //删除
                layer.confirm('确定退选【'+data.cname+'】这个课程吗', function(index){
                    //向服务端发送删除指令
                    $.post("dropcou",{cid:data.cid},function(res){
                        layer.msg(res);
                        //刷新数据 表格
                        tableIns.reload();
                    })
                });
            }
        });




    })
            </script>
</body>
</html>